package www.sofn.com.config;


import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.hibernate.validator.HibernateValidator;
import org.hibernate.validator.HibernateValidatorConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(value = HibernateValidatorConfiguration.class)
public class ValidatorConfiguration {
    @Bean
    public Validator init(){
        HibernateValidatorConfiguration configure = Validation.byProvider( HibernateValidator.class ).configure();
        final ValidatorFactory validatorFactory = configure.failFast(true).buildValidatorFactory(); //开启快速校验模式(只要有一个校验失败则返回)
        return validatorFactory.getValidator();

    }
}
